import 'package:flutter/material.dart';

import './page/home.dart';

import './page/not_found_page.dart';

import './page/base/base.dart';
import './page/base/text_demo.dart';
import './page/base/button_demo.dart';
import './page/base/image_demo.dart';
import './page/base/select_demo.dart';
import './page/base/form_demo.dart';
import './page/base/progress_demo.dart';

import './page/layout/layout.dart';
import './page/layout/line_demo.dart';
import './page/layout/flex_demo.dart';
import './page/layout/wrap_demo.dart';
import './page/layout/stack_demo.dart';
import './page/layout/align_demo.dart';

import './page/container/container.dart';
import './page/container/padding_demo.dart';
import './page/container/constraint_demo.dart';
import './page/container/decorate_demo.dart';
import './page/container/transform_demo.dart';
import './page/container/container_demo.dart';
import './page/container/clip_demo.dart';
import './page/container/scaffold_demo.dart';
import './page/container/scaffold_demo2.dart';

import './page/scroll/scroll.dart';
import './page/scroll/scroll_demo.dart';
import './page/scroll/list_demo.dart';
import './page/scroll/grid_demo.dart';
import './page/scroll//custom.dart';
import './page/scroll/listen.dart';

import './page/function/function.dart';
import './page/function/back_demo.dart';
import './page/function/theme_demo.dart';
import './page/function/future_demo.dart';
import './page/function/dialog_demo.dart';
import './page/function/event_demo.dart';
import './page/function/notification_demo.dart';
import './page/function/gesture_demo.dart';

import './page/custom/custom.dart';
import './page/custom/turn_box_demo.dart';
import './page/custom/paint_demo.dart';

class MyRoute {
  // 路由表
  static final Map<String, WidgetBuilder> routeTable = {
    '/' : (content) => Home(),

    '/base/base' : (content) => Base(),
    '/base/text' : (content) => TextDemo(),
    '/base/button' : (content) => ButtonDemo(),
    '/base/image' : (content) => ImageDemo(),
    '/base/select' : (content) => SelectDemo(),
    '/base/form' : (content) => FormDemo(),
    '/base/progress' : (content) => ProgressDemo(),

    '/layout/layout' : (content) => Layout(),
    '/layout/line' : (content) => LineDemo(),
    '/layout/flex' : (content) => FlexDemo(),
    '/layout/wrap' : (content) => WrapDemo(),
    '/layout/stack' : (content) => StackDemo(),
    '/layout/align' : (content) => AlignDemo(),

    '/container/container' : (content) => ContainerType(),
    '/container/padding' : (content) => PaddingDemo(),
    '/container/constraint' : (content) => ConstraintDemo(),
    '/container/decorate' : (content) => DecorateDemo(),
    '/container/transform' : (content) => TransformDemo(),
    '/container/container_demo' : (content) => ContainerDemo(),
    '/container/clip' : (content) => ClipDemo(),
    '/container/scaffold' : (content) => ScaffoldDemo(),
    '/container/scaffold2' : (content) => ScaffoldDemo2(),

    '/scroll/scroll' : (content) => Scroll(),
    '/scroll/scroll_demo' : (content) => ScrollDemo(),
    '/scroll/list' : (content) => InfiniteListView(),
    '/scroll/grid' : (content) => GridDemo(),
    '/scroll/custom' : (content) => CustomScroll(),
    '/scroll/listen' : (content) => ScrollListen(),

    '/function/function' : (content) => FunctionType(),
    '/function/back' : (content) => BackDemo(),
    '/function/theme' : (content) => ThemeDemo(),
    '/function/future' : (content) => FutureDemo(),
    '/function/dialog' : (content) => DialogDemo(),
    '/function/event' : (content) => EventDemo(),
    '/function/notification' : (content) => NotificationDemo(),
    '/function/gesture' : (content) => GestureDemo(),

    '/custom/custom' : (content) => Custom(),
    '/custom/turn_box' : (content) => TurnBoxDemo(),
    '/custom/paint' : (content) => PaintDemo(),
  };

  // 动态生成路由
  static final onGenerateRoute = (RouteSettings settings) {
    // 从路由表得到builder
    final name = settings.name;
    var builder = routeTable[name];

    // 如果路由表中未定义，跳转到未定义路由页面
    if (builder == null) {
      builder = (content) => NotFoundPage();
    }

    // 构建动态的route
    final route = MaterialPageRoute(
      builder: builder,
      settings: settings,
    );

    return route;
  };
}